package com.xiaoshuidi.cloud.framework.pay.core.enums;

import cn.hutool.core.util.ArrayUtil;
import com.xiaoshuidi.cloud.framework.pay.core.client.PayClientConfig;
import com.xiaoshuidi.cloud.framework.pay.core.client.impl.alipay.AlipayPayClientConfig;
import com.xiaoshuidi.cloud.framework.pay.core.client.impl.tonglian.TonglianClientConfig;
import com.xiaoshuidi.cloud.framework.pay.core.client.impl.wx.WXPayClientConfig;
import com.xiaoshuidi.cloud.framework.pay.core.client.impl.yinlian.YinlianClientConfig;
import com.xiaoshuidi.cloud.framework.pay.core.client.impl.tongshangyun.TongshangyunClientConfig;
import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * 支付渠道的编码的枚举
 * 枚举值
 *
 * @author
 */
@Getter
@AllArgsConstructor
public enum PayChannelEnum {
    // 微信官方
    WX_PUB("wx_pub", "微信 JSAPI 支付", "微信", WXPayClientConfig.class), // 公众号网页
    WX_MINIAPP("wx_miniapp", "微信小程序支付", "微信", WXPayClientConfig.class),
    WX_APP("wx_app", "微信 App 支付", "微信", WXPayClientConfig.class),
    WX_NATIVE("wx_native", "微信 native 支付", "微信", WXPayClientConfig.class),
    // 支付宝官方
    ALIPAY_PC("alipay_pc", "支付宝 PC 网站支付", "支付宝", AlipayPayClientConfig.class),
    ALIPAY_WAP("alipay_wap", "支付宝 Wap 网站支付", "支付宝", AlipayPayClientConfig.class),
    ALIPAY_APP("alipay_app", "支付宝App 支付", "支付宝", AlipayPayClientConfig.class),
    ALIPAY_QR("alipay_qr", "支付宝扫码支付", "支付宝", AlipayPayClientConfig.class),
//    // 通联(未使用)
//    TONGLIAN_MINIAPP("tonglian_wx_miniapp", "通联微信小程序支付", "微信", TonglianClientConfig.class),
    // 银联
    YINLIAN_WX_MINIAPP("yinlian_wx_miniapp", "银联微信小程序支付", "微信", YinlianClientConfig.class),
    YINLIAN_ALIPAY_MINIAPP("yinlian_alipay_miniapp", "银联支付宝小程序支付", "支付宝", YinlianClientConfig.class),
    YINLIAN_ALIPAY_APP("yinlian_alipay_app", "银联支付宝App支付", "支付宝", YinlianClientConfig.class),
    YINLIAN_WX_APP("yinlian_wx_app", "银联微信App支付", "微信", YinlianClientConfig.class),

    TONGSHANGYUN_WX_MINIAPP("tongshangyun_wx_miniapp", "收银宝微信小程序收银台支付", "通商云微信", TongshangyunClientConfig.class),

    TONGSHANGYUN_ALIPAY_MINIAPP("tongshangyun_alipay_miniapp", "收银宝支付宝小程序收银台支付", "通商云支付宝", TongshangyunClientConfig.class),
    // 通联收银台
    TONGLIAN_MINIAPP_CASHIER("tonglian_wx_miniapp", "通联微信小程序支付", "微信", TonglianClientConfig.class),
    TONGLIAN_ALIPAY_CASHIER("tonglian_alipay_miniapp", "通联支付宝小程序支付", "支付宝", TonglianClientConfig.class),
    ;

    /**
     * 编码
     * <p>
     * 参考 https://www.pingxx.com/api/支付渠道属性值.html
     */
    private final String code;
    /**
     * 名字
     */
    private final String name;
    /**
     * 简称
     */
    private final String shotName;
    /**
     * 配置类
     */
    private final Class<? extends PayClientConfig> configClass;

    /**
     * 微信支付
     */
    public static final String WECHAT = "WECHAT";

    /**
     * 支付宝支付
     */
    public static final String ALIPAY = "ALIPAY";

    /**
     * 银联支付
     */
    public static final String YINLIAN = "YINLIAN";

    public static PayChannelEnum getByCode(String code) {
        return ArrayUtil.firstMatch(o -> o.getCode().equals(code), values());
    }

}
